package Uploaded;

use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use LWP::UserAgent;
use URI::Escape;

my $cookie_jar = HTTP::Cookies->new(
    file => "F:\\perl\\spreader\\cookies\\uploadedto.dat",
    autosave => 1,
  );

my $browser = LWP::UserAgent->new();

$browser->cookie_jar($cookie_jar);


sub login 
{
	my $response = HTTP::Request->new(POST => "http://www.uploaded.to/login?coo=1");
	$response->content("email=260892;password=foaacss");
	
	return 1;
}

sub upload 
{
	shift @local_files = shift;
	my @download_links = ();

	my $response = $browser->get('http://uploaded.to/api/uploadserver');
	my $upload_server = $response->decoded_content;

	foreach my $current_local_file (@local_files)
	{
		my  = (int rand(10000)).'0'.(int rand(10000));

		my $response = $browser->post(
		  $upload_server.'up?upload_id='.$uid,
		  ['file1x' => [$current_local_file],
		  ],
		  'Content_Type' => 'form-data',
		);

		my $response = HTTP::Request->new(POST => "http://www.uploaded.to/home");
		$response->content("lang=de;ajax=lastuploads");

		$html = $browser->request($response)->as_string;

		if($html =~ m!>(http://uploaded.to/\?id=.*?)<!gs)
		{
			push(@download_links, $1);
		}
	}
	return @download_links;
}

1;